package com.example.demo.es.controller;

import com.example.demo.es.service.EmploService;
import com.example.demo.es.vo.Employee;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
public class TestEsController {

    final
    EmploService emploService;

    public TestEsController(EmploService emploService) {
        this.emploService = emploService;
    }

    @RequestMapping("/test")
    public List<Employee> test(@RequestParam String name) {

        Employee employee = new Employee(10L,"fox666",1,32,"长沙麓谷");
        //插入文档
        emploService.save(employee);

        //根据id查询
        Optional<Employee> result = emploService.findById(1L);

        //根据name查询
        List all = emploService.findByName(name);
        return all;
    }
}
